package com.bw.lib_widget.test

import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup

/**
 * @author zhy
 * @date 2025-09-22 14:10
 * @description
 */
class MyViewGroup: ViewGroup {

    constructor(context: Context?): super(context){
    }
    constructor(context: Context?, attrs: AttributeSet?): super(context, attrs){

    }
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int): super(context, attrs, defStyleAttr){

    }

    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        //必须测量子控件的大小,不然在onLayout中无法获得子控件的宽度和高度
        measureChildren(widthMeasureSpec, heightMeasureSpec)
    }
    override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
        val child = getChildAt(0)
        child.layout(0,0,child.measuredWidth,child.measuredHeight)
    }
}